//
//  NSString+Common.h
//
//  Created by Alexi on 12-11-5.
//  Copyright (c) 2012年 . All rights reserved.
//

#import <Foundation/Foundation.h>

char pinyinFirstLetter(unsigned short hanzi);

@interface NSString (Common)

// 将str加密成本地保存的文件名
+ (NSString *)md5String:(NSString *)str;
- (NSString *)md5;

-(NSString*)firstPinYin;

//是否为空
+ (BOOL)isEmpty:(NSString *)string;

/**
 compare two version
 @param sourVersion *.*.*.*
 @param desVersion *.*.*.*
 @returns No,sourVersion is less than desVersion; YES, the statue is opposed
 */
+(BOOL)compareVerison:(NSString *)sourVersion withDes:(NSString *)desVersion;

//当前字符串是否只包含空白字符和换行符
- (BOOL)isWhitespaceAndNewlines;

//去除字符串前后的空白,不包含换行符
- (NSString *)trim;

//去除字符串中所有空白
- (NSString *)removeWhiteSpace;
- (NSString *)removeNewLine;

//将字符串以URL格式编码
- (NSString *)stringByUrlEncoding;

/*!
 @brief     大写第一个字符
 @return    格式化后的字符串
 */
- (NSString *)capitalize;

//以给定字符串开始,忽略大小写
- (BOOL)startsWith:(NSString *)str;
//以指定条件判断字符串是否以给定字符串开始
- (BOOL)startsWith:(NSString *)str Options:(NSStringCompareOptions)compareOptions;


//以给定字符串结束，忽略大小写
- (BOOL)endsWith:(NSString *)str;
//以指定条件判断字符串是否以给定字符串结尾
- (BOOL)endsWith:(NSString *)str Options:(NSStringCompareOptions)compareOptions;

//包含给定的字符串, 忽略大小写
- (BOOL)containsString:(NSString *)str;
//以指定条件判断是否包含给定的字符串
- (BOOL)containsString:(NSString *)str Options:(NSStringCompareOptions)compareOptions;

//判断字符串是否相同，忽略大小写
- (BOOL)equalsString:(NSString *)str;

/**
 *  网址验证
 *
 *  @param url 网址
 *
 *  @return YES or NO
 */
-(BOOL)isValidateUrl: (NSString *)url;

/**
 *  邮箱验证
 *
 *  @param email 邮箱地址
 *
 *  @return YES or NO
 */
+(BOOL)isValidateEmail: (NSString *)email;

/**
 *  手机号码验证
 *
 *  @param phoneNumber 手机号码
 *
 *  @return YES or NO
 */
+(BOOL)isValidatePhoneNumber: (NSString *)phoneNumber;

/**
 *  身份证号码验证
 *
 *  @param identityCard 身份证号码
 *
 *  @return YES or NO
 */
+(BOOL)isValidateIdentityCard: (NSString *)identityCard;


/**
 *  输入正则表达式 匹配 字符串
 *
 *  @param regExpx 正则表达式
 *  @param string 字符串
 *
 *  @return YES or NO
 */
+(BOOL)validateWithRegExp: (NSString *)regExpx string: (NSString *)string;

/**
 *  通过图片data数据的第一个字节来获取图片的扩展名
 *
 *  @param data 图片data数据
 *
 *  @return NSString格式的图片扩展名
 */
+(NSString *)contentTypeForImageData: (NSData *)data;


//根据时间戳获取星期几
+ (NSString *)getWeekDayFordate:(long long)data;
+ (NSInteger)getWeekDayForTimeamp:(long long)data;
+ (NSString *)timeWithTimeIntervalString:(NSString *)timeString;

- (NSString *)emjoiText;
//获取当前时间的时间戳
+ (NSString *)getCurrentTimestamp;

#pragma mark Hashing
#if kSupportGTM64
- (NSString *)base64Encoding;
#endif

- (NSString *)valueOfLabel:(NSString *)label;

- (NSString *)substringAtRange:(NSRange)rang;


// 是否带有表情府

- (NSUInteger)utf8Length;

- (BOOL)isContainsEmoji;

//递归计算符合规定的文本长度
- (NSString *)cutBeyondTextInLength:(NSInteger)maxLenth;

- (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font;
- (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font breakMode:(NSLineBreakMode)breakMode;
- (CGSize)textSizeIn:(CGSize)size font:(UIFont *)font breakMode:(NSLineBreakMode)breakMode align:(NSTextAlignment)alignment;

//字典字符串转换
+ (NSString *)convertToJsonData:(NSDictionary *)dict;
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString;
@end

